package org.dei.perla.sys.llqruntime;


import java.util.ArrayList;

import org.dei.perla.parser.expressions.*;
import org.dei.perla.sys.llqruntime.datastructures.Record;

/**
 * Permette di valutare un'espressione
 * @author diego
 *
 */
public class ExpressionEvaluator {
	
		
	public static boolean evaluate(Record parRecord, Node parNode) {
		
		ExpressionAnalyzer ea = new ExpressionAnalyzer();
		ArrayList<NodeLogicalObjectAttribute> ar = ea.getNodeArrayList(parNode);
		
		for (NodeLogicalObjectAttribute t : ar) {
			
			t.setLogicalObjectValue(parRecord.getField(t.getLogicalObjectAttributeName()));
		}
		
		try {
			
			System.out.println(parNode);
			if (parNode.getResult().getValueLogic() == LogicValue.TRUE) return true;
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
}
